package com.lovo.homework.Day;

import java.sql.SQLIntegrityConstraintViolationException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Day7_11 {
    private List<Card> list = new ArrayList();
    private List<Card> list1 = new ArrayList();
    private List<Card> list2 = new ArrayList();
    private List<Card> list3 = new ArrayList();
    private List<Card> list4 = new ArrayList();
    private Card card = new Card();

    //初始化54张牌
    public void creat() {
        for (int i = 0; i <= 15; i++) {
            if (i <= 13) {
                card.setPoint(i + "");
                for (int j = 0; j <= 3; j++) {
                    card.setType(j + "");
                    list.add(new Card(card.getPoint(), card.getType()));
                }
            } else {
                card.setPoint(i + "");
                card.setType("4");
                list.add(new Card(card.getPoint(), card.getType()));
            }
        }
        System.out.println("list" + list);
    }


    //洗牌
    public void shuffleCards() {
        Collections.shuffle(list);
    }

    //发牌
    public void sendCard() {
        list1 = list.subList(0, 17);
        list1.sort(new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                int a = Integer.parseInt(o1.getPoint());
                int b = Integer.parseInt(o2.getPoint());
                return a - b;
            }
        });

        list2 = list.subList(17, 34);
        list2.sort(new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                int a = Integer.parseInt(o1.getPoint());
                int b = Integer.parseInt(o2.getPoint());
                return a - b;
            }
        });

        list3 = list.subList(34, 52);
        list3.sort(new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                int a = Integer.parseInt(o1.getPoint());
                int b = Integer.parseInt(o2.getPoint());
                return a - b;
            }
        });

        list4 = list.subList(52, 55);
        list4.sort(new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                int a = Integer.parseInt(o1.getPoint());
                int b = Integer.parseInt(o2.getPoint());
                return a - b;
            }
        });

        System.out.println("玩家1" + list1);
        System.out.println("玩家2" + list2);
        System.out.println("玩家3" + list3);
        System.out.println("底牌" + list4);
    }


    public static void main(String[] args) {
        Day7_11 test = new Day7_11();
        test.creat();
        test.shuffleCards();
        test.sendCard();

    }

}


//扑克牌类
class Card {
    //分数("0"-3，"1"-4，"2"-5，"3"-6,"4"-7，"5"-8，"6"-9，"7"-10,"J"-11,"Q"-12,"K"-13,"A"-14,"2"-15,"小王"-16，”大王“-17
    private String point;
    //花色("0"-黑桃，"1"-梅花，"2"-红桃，"3"-方块,"4"-大小王)
    private String type;

    //构造器
    public Card() {

    }

    public Card(String point, String type) {
        this.point = point;
        this.type = type;
    }

    //重写toString
    @Override
    public String toString() {
        return "卡牌{" +
                "点数='" + point + '\'' +
                ", 花色='" + type + '\'' +
                '}';
    }

    public String getPoint() {
        return point;
    }

    public void setPoint(String point) {
        this.point = point;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
}